package edu.vanderbilt.multicast.android;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;

import android.os.Environment;
import android.util.Log;
import edu.vanderbilt.vshare.multicast.SRInputStream;

public class StreamingClient {

	public class FileClient implements Runnable {

		byte [] sample_file;
		byte [] docandu_file;
		
		public void run () {
			SRInputStream stream = new SRInputStream();

			//stream.listen("228.5.6.7");
			stream.listen("228.5.6.8");
			//stream.listen("228.5.6.10");
			//stream.listen("228.5.6.11");
			
			byte [] sample_file = stream.read("sample.3gp");
			byte [] docandu_file = stream.read("documentariesandyou.mp4");
			

			try {
				File root = Environment.getExternalStorageDirectory ();
				if (root.canWrite ()) {
					
					File videofile;
					FileOutputStream writer;
					
					videofile = new File (root, "sample.3gp");
					if (! videofile.exists ()) {
					writer = new FileOutputStream (videofile);
					writer.write (sample_file);
					writer.close ();
					System.out.println ("Written sample.3gp to sdcard");
					}
					
					if (! videofile.exists ()) {
					videofile = new File (root, "documentariesandyou.mp4");
					writer = new FileOutputStream (videofile);
					writer.write (docandu_file);
					writer.close ();
					System.out.println ("Written documentariesandyou.mp4 to sdcard");
					}
				}
			} catch (IOException e) {
				Log.e ("XMLReader", "Could not write file " + e.getMessage ());
			}


		}

	}


}
